import { PipelineStatus, Role, TaskStatus, PodStatus } from '@/enums/pipelineEnum';
import { DictEnum } from '@/enums/commonEnum';
import { ArtifactRole } from '@/enums/artifactRepositoryEnum';
import { useGlobal } from '@/store/modules/global';
const useGlobalStore = useGlobal();

// 全局字典表
export const languageOptinos = useGlobalStore.getDictionaryTable(DictEnum.languageOptinos); // 语言选项
export const componentData = useGlobalStore.getDictionaryTable(DictEnum.componentData); // 组件数据
export const deploymentProgressList = useGlobalStore.getDictionaryTable(DictEnum.deploymentProgress); // 部署进度

// parentUuid为'0'代表是首个节点
export const firstTaskParentUuid = '0';

interface PipelineStatusData {
  color: string;
  text: string;
  icon: string;
}

interface PodStatusData {
  color: string;
  text: string;
}

export const pipelineStatusMap: Record<PipelineStatus, PipelineStatusData> = {
  running: { color: '#2890ff', text: '运行中', icon: 'running-pipeline-icon' },
  waiting: { color: '#eec000', text: '等待中', icon: 'waiting-icon' },
  success: { color: '#1fab18', text: '成功', icon: 'success-icon' },
  fail: { color: '#e6371c', text: '失败', icon: 'fail-icon' },
  terminated: { color: '#eb5f49', text: '已终止', icon: 'terminated-icon' },
};

export const taskStatusMap: Record<TaskStatus, PipelineStatusData> = {
  notStart: { color: '#989A9C', text: '未开始', icon: 'waiting-icon' },
  running: { color: '#2890ff', text: '运行中', icon: 'running-icon' },
  success: { color: '#1fab18', text: '成功', icon: 'success-icon' },
  fail: { color: '#e6371c', text: '失败', icon: 'fail-icon' },
  timeout: { color: '#e6371c', text: '超时', icon: 'fail-icon' },
  unknown: { color: '#eec000', text: '未知', icon: 'waiting-icon' },
  waiting: { color: '#eec000', text: '暂停', icon: 'waiting-icon' },
  terminated: { color: '#eb5f49', text: '已终止', icon: 'terminated-icon' },
};

export const podStatusMap: Record<PodStatus, PodStatusData> = {
  Pending: { color: '#989A9C', text: '等待中' },
  Running: { color: '#2890ff', text: '运行中' },
  Succeeded: { color: '#1fab18', text: '成功' },
  Failed: { color: '#e6371c', text: '失败' },
  Unknown: { color: '#989A9C', text: '未知' },
  Waiting: { color: '#eec000', text: '等待' },
  Terminated: { color: '#eb5f49', text: '已终止' },
};

export const triggerTypeMap: Record<number, string> = {
  1: '周期触发',
  2: '单次触发',
  3: '页面手动触发',
};

// 验证有关code的正则
export const validatorCode = /^(?=.{1,50}$)[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$/;

// 验证有关url的正则
export const validatorUrl = /^(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?$/;

// 验证必须是http://或者https://开头的url
export const validatorHttpUrl = /^(http|https):\/\//;

// 验证需是数字和字母和中划线或下划线的组合
export const validatorCodeOrName = /^[a-zA-Z0-9]+([-_][a-zA-Z0-9]+)*$/;

// 密码至少包含8个字符，至少有一个大写或小写字母，不包含中文字符，也不包含空格
export const validatorPassword = /^(?=.*[a-zA-Z])(?!.*[\u4e00-\u9fa5])(?!.*\s).{8,}$/;

// 制品仓库角色
export const artifactRolesMap: Record<ArtifactRole, string> = {
  manager: '管理者',
  developer: '开发者',
  // ordinary: '普通人员',
};

// 流水线角色
export const rolesMap: Record<Role, string> = {
  manager: '管理者',
  developer: '开发者',
};
// 制品类型
export const artifactTypeOptions = [
  // { value: 'GENERIC', label: 'Generic' },
  { value: 'DOCKER', label: 'Docker' },
  { value: 'MAVEN', label: 'Maven' },
  { value: 'NPM', label: 'Npm' },
];

// 存储策略
export const storagePolicyOptions = [
  { value: 'RELEASE', label: 'RELEASE' },
  { value: 'SNAPSHOT', label: 'SNAPSHOT' },
  { value: 'MIXED', label: 'MIXED' },
];
